package com.jy.rhin.support.polymorphism.convertor;


import com.jy.framework.base.utils.Converter;
import com.jy.framework.base.utils.DateUtil;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author dhl
 * @date 2022/6/21
 * @Description
 */
public class QueryValueUtils {

    private QueryValueUtils(){
        throw new IllegalStateException("QueryValueUtils class");
    }

    /**
     * 获取字符串类型参数值
     * @param key
     * @param map
     * @return
     */
    public static String getStringValue(String key, Map<String, List<String>> map) {
        if (map.containsKey(key)) {
            return map.get(key).get(0);
        }
        return "";
    }

    /**
     * 获取时间类型参数值
     * @param key
     * @param map
     * @return
     */
    public static Date getDateValue(String key, Map<String, List<String>> map) {
        if (map.containsKey(key)) {
            return DateUtil.getDateByString(Converter.DATE_FORMAT, map.get(key).get(0));
        }
        return null;
    }

    /**
     * 获取列表类型参数值
     * @param key
     * @param map
     * @return
     */
    public static List<String> getListValue(String key, Map<String, List<String>> map) {
        if (map.containsKey(key)) {
            return map.get(key);
        }
        return Collections.emptyList();
    }
}
